#pragma once
#pragma warning (disable:4996)
#include"model.h"
#include<stdio.h>
#include<stdlib.h>
#include"billing_service.h"

/*
int saveBilling(Billing* bp) {
	FILE* fp = fopen("data\\billing.ams", "ab");
	fwrite(bp, sizeof(Billing), 1, fp);
	fclose(fp);
}
*/

void readBillingFile() {
	FILE* fp = fopen("data\\billing.ams", "rb");
	fseek(fp, 0, SEEK_END);
	int sizeB = ftell(fp);
	int n = sizeB / sizeof(Billing);
	Billing* pBill;
	fseek(fp, 0, SEEK_SET);
	for (int i = 0; i < n; i++) {
		pBill = (Billing*)malloc(sizeof(Billing));
		fread(pBill, sizeof(Billing), 1, fp);
		insertNodeB(pBill);
	}
	fclose(fp);
}

void writeBillingFile(Billing*BillList) {
	FILE* fp = fopen("data\\billing.ams", "wb");
	for (Billing* p = BillList->next;p!=NULL; p = p->next) {
		fwrite(p, sizeof(Billing), 1, fp);
	}
	fclose(fp);
}